package com.example.es;

import com.alibaba.fastjson2.JSONObject;
import org.apache.http.HttpHost;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

/**
 * @Author：wlz
 * @Package：com.example.es
 * @Project：redis
 * @name：ESTest_Index_Create
 * @Date：2023/4/15 22:18
 * @Filename：ESTest_Index_Create
 */
public class ESTest_Doc_Update {
    public static void main(String[] args) throws IOException {
        //创建
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost",9200)));
        //修改数据
        UpdateRequest request = new UpdateRequest();
        request.index("user1").id("1001");

        request.doc(XContentType.JSON,"sex","女");
        UpdateResponse index = client.update(request, RequestOptions.DEFAULT);

        //响应状态
        System.out.println(index.getResult());

        //关闭
        client.close();
    }
}
